#include "mycp.h"

int mycp(char *path1, char *path2, char mode)
{

    FILE *f2;
    switch (mode)
    {
    case 'w':
    {
        f2 = fopen(path2, "w");
    }
    case 'a':
    {
        f2 = fopen(path2, "a");
        FILE *f1 = fopen(path1, "r");
        char buff[BUFFSIZE];
        int len;
        while ((len = fread(buff, sizeof(char), BUFFSIZE, f1)) != 0)
        {
            if (len == -1)
            {
                return -1;
            }
            else
            {
                len = fwrite(buff, sizeof(char), len, f2);
                if (len == -1)
                {
                    return -1;
                }
            }
        }
        return 0;
    }
    default:
        return -1;
        break;
    }
}